//
//  YGArticleHeaderView.m
//  yuanshangyiliao
//
//  Created by icholab on 2021/5/3.
//

#import "YGArticleHeaderView.h"

@interface YGArticleHeaderView ()
@property (nonatomic, strong) UIButton  *subBtn;
@property (nonatomic, strong) UIImageView  *coverImageView;

@end
@implementation YGArticleHeaderView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self addSubview:self.coverImageView];
        [self addSubview:self.subBtn];
        
        [self.coverImageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.left.right.bottom.mas_equalTo(0);
        }];
        
        [self.subBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.width.mas_equalTo(65);
            make.height.mas_equalTo(23);
            make.bottom.mas_equalTo(-10);
            make.right.mas_equalTo(self).offset(-10);
        }];
    }
    return self;
}

- (void)configureModel:(YGArticleListModel *)model{
    [self.coverImageView sd_setImageWithURL:[NSURL URLWithString:model.banner]];
    self.subBtn.selected = model.isSubscribe;
}

- (void)clicSubAction{
    self.subBtn.selected = !self.subBtn.selected;
    if (self.ClickBlock) {
        self.ClickBlock(self.subBtn.selected);
    }
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

#pragma mark - Getter

- (UIButton *)subBtn
{
    if(!_subBtn){
        _subBtn = [[UIButton alloc] init];
        [_subBtn setTitle:@"+ 订阅" forState:UIControlStateNormal];
        [_subBtn setTitle:@"取消订阅" forState:UIControlStateSelected];
        [_subBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        _subBtn.layer.borderColor = [UIColor whiteColor].CGColor;
        _subBtn.layer.borderWidth = 0.5;
        _subBtn.clipsToBounds = YES;
        _subBtn.layer.cornerRadius = 4;
        _subBtn.titleLabel.font = [UIFont systemFontOfSize:12];
        [_subBtn addTarget:self action:@selector(clicSubAction) forControlEvents:UIControlEventTouchUpInside];
    }
    return _subBtn;
}

- (UIImageView *)coverImageView
{
    if(!_coverImageView){
        _coverImageView = [[UIImageView alloc] init];
    }
    return _coverImageView;
}

@end
